/*
* Copyright (c) 2011 Connection Road.  All rights reserved.
* This program and the accompanying material are made available
* under the terms of the Eclipse Public Licnese v1.0 which is
* available at http://www.eclipse.org/legal/epl-v10.html
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

namespace CrSyncFilesUtils
{
    /// <summary>
    /// Just a container and nothing more.
    /// </summary>
    [Serializable]
    [XmlRoot("CrSyncFiles")]
    public partial class FileSyncPairDocumentInfo
    {
        public string Company { get; set; }
        public string ApplicationVersion { get; set; }
        public string ApplicationName { get; set; }
        public string CopyText { get; set; }
        
        public CrSyncFilesCustomDictionary ExtendedInfo { get; set; } 
        public List<FileSyncPairInfo> FolderPairs { get; set; }

        public FileSyncPairDocumentInfo()
        {
            Init();
        }

        public FileSyncPairDocumentInfo(Dictionary<string,FileSyncPairInfo> folderPairs)
        {
            Init();
            SetFolderPairs(folderPairs);
        }

        public FileSyncPairDocumentInfo(ICollection<FileSyncPairInfo> folderPairs)
        {
            Init();
            SetFolderPairs(folderPairs);
        }

        public Dictionary<string,FileSyncPairInfo> GetFolderPairs()
        {
            var dictionary = new Dictionary<string, FileSyncPairInfo>();
            foreach (var pair in FolderPairs)
            {
                dictionary[pair.UniqueIdentifier] = pair;
            }
            return dictionary;
        }

        public void Init()
        {
            Company = "Connection Road";
            ApplicationName = "CRSyncFiles";
            ApplicationVersion = "1.0.0.0";
            CopyText = "Copyright 2011 ConnectionRoad.  All rights reserved.";

            FolderPairs = new List<FileSyncPairInfo>();
            ExtendedInfo = new CrSyncFilesCustomDictionary();
        }


        public void SetFolderPairs(ICollection<FileSyncPairInfo> folderPairs)
        {
            FolderPairs = new List<FileSyncPairInfo>(folderPairs);
        }

        public void SetFolderPairs(Dictionary<string, FileSyncPairInfo> folderPairs)
        {
            FolderPairs = new List<FileSyncPairInfo>();
            foreach (var fileSyncPairInfo in folderPairs.Values.ToList())
            {
                FolderPairs.Add(fileSyncPairInfo);
            }
        }
    }
}
